// Tags:
#include <algorithm>
#include <cstdio>

typedef long long ll;
const int N = 2e3 + 5, M = 11;
int n, m, cnt, x[N], y[N], blocks;
int e_cnt, f[N];

struct Edge {
  int v, u, w;
  inline bool operator<(const Edge &rhs) const { return w < rhs.w; }
} e[N * N];

inline void add(int u, int v, int w) {
  e[++e_cnt].v = v, e[e_cnt].u = u, e[e_cnt].w = w;
}

struct Pol {
  int k, c;
  int p[N];
} pol[M];

inline int sqr(int x) { return x * x; }

int find(int x) { return f[x] == x ? x : f[x] = find(f[x]); }

inline bool merge(int x, int y) {
  if (find(x) != find(y)) {
    f[find(x)] = find(y);
    --blocks;
    return true;
  } else {
    return false;
  }
}

inline void init() {
  for (int i = 1; i <= n; ++i) f[i] = i;
  blocks = n;
}

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen64("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen64("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("graph.in", "r", stdin);
  freopen("graph.out", "w", stdout);
#endif
#endif

  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) { scanf("%d%d", &x[i], &y[i]); }
  for (int i = 1; i <= n; ++i) {
    for (int j = i + 1; j <= n; ++j) {
      add(i, j, sqr(x[i] - x[j]) + sqr(y[i] - y[j]));
    }
  }
  for (int i = 1; i <= m; ++i) {
    Pol &tmp = pol[i];
    scanf("%d%d", &tmp.k, &tmp.c);
    for (int j = 1; j <= tmp.k; ++j) scanf("%d", &tmp.p[j]);
  }
  std::sort(e + 1, e + e_cnt + 1);
  init();
  for (int i = 1, j = 0; i <= e_cnt; ++i) {
    if (merge(e[i].u, e[i].v)) {
      e[++j] = e[i];
      if (blocks == 1) {
        e_cnt = j;
        break;
      }
    }
  }
  ll ans = 0x7fffffffffffffff;
  for (int i = 0, lim = 1 << m; i < lim; ++i) {
    init();
    ll tmpans = 0;
    for (int j = 0; j < m; ++j) {
      Pol &tmp = pol[j + 1];
      if ((i >> j) & 1) {
        tmpans += tmp.c;
        for (int k = 1; k <= tmp.k && blocks > 1; ++k)
          merge(tmp.p[1], tmp.p[k]);
      }
    }
    if (tmpans >= ans) continue;
    for (int i = 1; i <= e_cnt && tmpans < ans && blocks > 1; ++i)
      if (find(e[i].u) != find(e[i].v)) {
        tmpans += e[i].w;
        merge(e[i].u, e[i].v);
      }
    if (tmpans < ans) ans = tmpans;
  }
  printf("%lld", ans);
  return 0;
}